package com.hltlq.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
public class BaseAction extends ActionSupport{

	private static final long serialVersionUID = 4790548663682377422L;

	/**
     * Convenience method to get the request
     * @return current request
     */
    protected HttpServletRequest getRequest() {
        return ServletActionContext.getRequest();
    }

    /**
     * Convenience method to get the response
     * @return current response
     */
    protected HttpServletResponse getResponse() {
        return ServletActionContext.getResponse();
    }

    /**
     * Convenience method to get the session. This will create a session if one doesn't exist.
     * @return the session from the request (request.getSession()).
     */
    protected HttpSession getSession() {
        return getRequest().getSession();
    }
    
    public String showMsg(String message) {
        StringBuffer sb = new StringBuffer();
        sb.append("<Script language=\"javaScript\">\r\n");
        sb.append("alert(\"");
        sb.append( message );
        sb.append("\");");
        sb.append("\r\n");
        sb.append("history.back();");
        sb.append("</Script>\r\n");
        try {
        	 getResponse().setContentType("text/html;charset=utf-8");
        	 getRequest().setCharacterEncoding("utf-8");
             PrintWriter out =  getResponse().getWriter();
             out.println( sb.toString() );
             out.flush();
        } catch (IOException e) {
             e.getMessage();
        }
        return null;
    }

}
